package com.cos.openapi.web.controller;

import com.cos.openapi.entity.AdminUser;
import com.cos.openapi.entity.Role;
import com.cos.openapi.pojo.JsonResult;
import com.cos.openapi.pojo.TableResult;
import com.cos.openapi.services.AdminUserServices;
import com.cos.openapi.services.RoleServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author: COS
 * @time: 2021/2/1 14:15
 * @description:
 */
@RestController
@RequestMapping("/sys/user")
public class AdminUserController {
    @Autowired
    private AdminUserServices adminUserServices;
    @Autowired
    private RoleServices roleServices;
    @RequestMapping("/table2")
    public TableResult table(Integer page, Integer limit, String realName, String email, Integer status) {
        //找业务层查询数据
        return null;
    }

    @RequestMapping("/table")
    public TableResult table2(@RequestParam Map<String, Object> map) {
        //找业务层查询数据
        //多个列表 使用map request json
        return adminUserServices.table(map);
    }

    @RequestMapping("/del")
    public JsonResult del(Integer[] ids) {
        return adminUserServices.del(ids);
    }

    @RequestMapping("/user_role")
    public List<Integer> user_role(Integer userId) {

        return adminUserServices.user_role(userId);
    }

    @RequestMapping("/role_tree")
    public List<Role> role_tree() {
        //roleServices
        return roleServices.getRoles();
    }

    @RequestMapping("/assign_role")
    public JsonResult assign_role(Integer userId,Integer[] roleIds){
        return adminUserServices.assign_role(userId,roleIds);
    }

    @RequestMapping("/add")
    public JsonResult add(AdminUser adminUser){
        return adminUserServices.add(adminUser);
    }
    @RequestMapping("/update")
    public JsonResult update(AdminUser adminUser){
        return adminUserServices.update(adminUser);
    }

}
